package cn.wolfcode.trip.base.service.impl;


import cn.wolfcode.trip.base.domain.MyOrder;
import cn.wolfcode.trip.base.mapper.MyOrderMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IMyOrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MyOrderServiceImpl implements IMyOrderService{
    @Autowired
    private MyOrderMapper myOrderMapper;

    @Override
    public int save(MyOrder myOrder) {
        Date date = new Date();
        myOrder.setCreateTime(date);
        return myOrderMapper.insert(myOrder);
    }

    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<MyOrder> myOrders = myOrderMapper.queryForList(qo);
        return new PageInfo(myOrders);
    }
    //已付款订单
    @Override
    public PageInfo getOrderByPaid(QueryObject qo,Long userId) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<MyOrder> list = myOrderMapper.getOrderByPaid(userId);
        return new PageInfo<MyOrder>(list);
    }
    //d待付款订单
    @Override
    public PageInfo getObligationOrder(QueryObject qo,Long userId) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<MyOrder> list = myOrderMapper.getObligationOrder(userId);
        return new PageInfo<MyOrder>(list);
    }

    @Override
    public void deleteOrderById(Long orderId) {
        myOrderMapper.deleteOrderById(orderId);
    }

    @Override
    public Integer getTotalCount(Long userId) {
        return myOrderMapper.getTotalCount(userId);
    }

    @Override
    public Integer getCounts(Long userId) {
        return myOrderMapper.getCounts(userId);
    }

    @Override
    public void updateState(Long orderId) {
        myOrderMapper.updateState(orderId);
    }

    @Override
    public MyOrder getProductInfo(Long orderId) {
        return myOrderMapper.getProductInfo(orderId);
    }


}
